<?php
//
namespace app\circle\controller\admin;

use app\circle\controller\PhpAnalysisController;
use app\circle\model\ThemeModel;
use app\circle\model\ThreplyModel;
use org\util\FileUtil;
use think\File;
use think\Request;

class ThemeController extends BaseController
{

    private $themeModel;
    private $threplyModel;

    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->themeModel = new ThemeModel();
        $this->threplyModel = new ThreplyModel();
    }

    /**
     * 首页
     * @return mixed
     */
    public function index()
    {
        $map        = [];
        $query      = $this->request->request();
        if($this->adminInfo['admin_power']==3){
            $circleModel = new \app\circle\model\CircleModel();
            $circleIds = $circleModel->where('admin_id',$this->adminInfo['admin_id'])->column('circle_id');
            $map['circle_id'] = ['in',$circleIds];
        }
        $themeName  = $this->request->param('theme_name');
        if (!empty($themeName)) {
            $map['theme_name'] = ['like', '%' . $themeName . '%'];
        }
        $list = $this->themeModel->where($map)->paginate(12, false, ['query' => $query]);
        $this->assign('list', $list);
        return $this->fetch();
    }

    /**
     * 设置字段状态
     */
    public function setField(){
        $themeId = $this->request->param('theme_id/d');
        $field = $this->request->param('field');
        $value = $this->request->param('value');
        $this->themeModel->where('theme_id',$themeId)->setField($field,$value);
        $this->success('操作成功！');
    }
    /**
     * 删除
     */
    public function del(){
        $themeId = $this->request->param('theme_id/d');
        $this->threplyModel->where('theme_id',$themeId)->delete();
        $this->themeModel->where('theme_id',$themeId)->delete();
        $this->success('删除成功！');
    }

    /**
     * 敏感词
     */
    public function sensitive()
    {
        if ($this->request->isPost()){
            $str=$this->request->param('text','');
            cache('sensitive',$str);
            $this->success('设置成功');
        }
        $words=cache('sensitive');
        $this->assign('words',$words);
        return $this->fetch();
    }

}
